<template>
  <el-dialog
    :visible.sync="visible"
    title="新增电话支持"
    width="500px"
    append-to-body
    :close-on-click-modal="false"
  >
    <el-form
      :model="form"
      ref="ruleForm"
      label-width="100px"
      :show-message="false"
    >
      <el-form-item label="联系人" prop="userName" required>
        <el-input v-model.trim="form.userName" placeholder="请输入联系人名称" :maxlength="10"></el-input>
      </el-form-item>
      <el-form-item label="联系电话" prop="userPhone" required>
        <el-input v-model.trim="form.userPhone" placeholder="请输入联系电话" :maxlength="11"></el-input>
      </el-form-item>
      <el-form-item label="联系人头像" prop="userAvatar" required>
        <ImageUpload  v-model="form.userAvatar" cropper />
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import ImageUpload from '@/components/ImageUpload';
import { addCustomerService } from '@/api/saas/customerService';

export default {
  components: {
    ImageUpload
  },
  data() {
    return {
      visible: false,
      form: {
        supportType: 1, // 0在线视频支持(专家) 1电话支持(自建联系人)
        expertIds: undefined, // 专家id,逗号分割
        userAvatar: undefined, // 联系人
        userName: undefined,
        userPhone: undefined
      },
    };
  },
  methods: {
    show() {
      this.visible = true;
      this.$nextTick(()=>{
        this.$refs.ruleForm.clearValidate();
      })
    },
    submit() {
      const that = this;
      that.$refs.ruleForm.validate((valid) => {
        if(valid){
          addCustomerService(that.form).then(()=>{
            that.$message.success('新增成功');
            that.visible = false;
            Object.assign(this.$data.form, this.$options.data().form);
            that.$emit('refresh');
          })
        }else{
          this.$message.error('请完善表单必填项!')
        }
      })
    }
  }
};
</script>
<style lang="scss" scoped></style>
